export function saveUrl(url) {
  console.log(url)
  uni.downloadFile({
    url: url,
    success: (res) => {
      if (res.statusCode === 200) {
        uni.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: function () {
            uni.showToast({
              title: "保存成功",
              icon: "none"
            });
          },
          fail(err) {
            if (err.errMsg == 'saveImageToPhotosAlbum:fail cancel') {
              uni.showModal({
                title: '提示',
                content: '您取消了保存',
                showCancel: false,
              })
              return
            }
            console.log(err.errMsg, 'err')
            uni.showModal({
              title: '提示',
              content: '需要您授权保存相册',
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  uni.openSetting({
                    success(settingdata) {
                      if (settingdata.authSetting['scope.writePhotosAlbum']) {
                        uni.showModal({
                          title: '提示',
                          content: '获取权限成功,再次保存图片即可成功',
                          showCancel: false,
                        })
                      } else {
                        uni.showModal({
                          title: '提示',
                          content: '获取权限失败，无法保存到相册',
                          showCancel: false
                        })
                      }
                    }
                  })
                }
              }
            })
          }
        });
      }
    }
  })
}

// 深拷贝
export function deClone(obj) {
  let result = Array.isArray(obj) ? [] : {}
  for (let key in obj) {
    if (typeof obj[key] === "object") {
      result[key] = deClone(obj[key])
    } else {
      result[key] = obj[key]
    }
  }
  return result
}

// 比对表单信息变动
export const reFomrVerify = (oldVal, newVal) => {
  const keys = Object.keys(oldVal);
  let flag = false;
  keys.forEach(key => {
    if (oldVal[key] !== newVal[key]) {
      flag = true
    }
  });

  return flag;
}
